<template>
  <base-layout>
    <template #searchPanel>
      <search-panel
        v-slot="{ form }"
        :addPer="'111'"
        :selectPer="'111'"
        addTitle="新增采购"
        @insert="add"
        @search="search"
        :showSearchButton="true"
        :showAddButton="true"
      >
        <el-select
          style="width: 200px"
          clearable
          v-model="form.storeId"
          placeholder="所属门店"
        >
          <el-option
            v-for="item in stores"
            :key="item.id"
            :value="item.id"
            :label="item.storeName"
          />
        </el-select>
        <el-select
          clearable
          style="width: 200px"
          v-model="form.type"
          placeholder="状态"
        >
          <el-option
            v-for="item in getDict(['置换类型'])['置换类型']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="form.client"
          clearable
          placeholder="采购编号"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #action="{ row }">
          <i
            class="el-icon-search"
            title="查看"
            style="margin-left: 15px; cursor: pointer"

            @click="handleDetails(row)"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"
            style="color: red; margin-left: 20px; cursor: pointer"

            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
    </template>
  </base-layout>
</template>
<script>
import baseMixin from '@/mixins/base'
import {
  getList,
  update,
  deleteById
} from '@/api/pre-sale/orderManagement/replacement'
import { getDict } from '@/utils/index'
import { getAllBrand, getSeries } from '@/api/after-sale/systemManage/carModel'
import { mapGetters } from 'vuex'

export default {
  mixins: [
    baseMixin({
      idName: 'id',
      findData: getList,
      updateData: update,
      deleteData: deleteById,
      dataName: ['content', 'totalRecords'],
      format(res) {
        return res.map((data) => {
          data.replacementPrice = data.replacementPrice === 1 ? '置换补差价' : '置换补贴'
          return data
        })
      }
    })
  ],
  computed: {
    ...mapGetters(['stores', 'storesCalue'])
  },
  data() {
    return {
      allBrand: [], // 品牌
      allSeries: [], // 车系
      getDict: getDict,
      form: {
        client: '' // 客户信息
      },
      tableColumnAttributes: [
        {
          name: '所属门店',
          value: 'storeName',
          type: 'text'
        },
        {
          name: '入库单号',
          value: 'carBrandName',
          type: 'text'
        },
        {
          name: '出库单号',
          value: 'carSeriesName',
          type: 'text'
        },
        {
          name: '是否前装',
          value: 'carModelName',
          type: 'text'
        },
        {
          name: '状态',
          value: 'color',
          type: 'text'
        },
        {
          name: '仓库',
          value: 'type',
          type: 'text'
        },
        {
          name: '仓位',
          value: 'replacementPrice',
          type: 'text'
        },
        {
          name: '精品编号',
          value: 'mileage',
          type: 'text'
        },
        {
          name: '精品一级类别',
          value: 'firstLicenseTime',
          type: 'text'
        },
        {
          name: '精品二级类别',
          value: 'displacement',
          type: 'text'
        },
        {
          name: '适用品牌/车系/车型',
          value: 'gearbox',
          type: 'text'
        },
        {
          name: '精品资源',
          value: 'clientName',
          type: 'text'
        },
        {
          name: '名称',
          value: 'clientPhone',
          type: 'text'
        },
        {
          name: '售价',
          value: 'displacement',
          type: 'text'
        },
        {
          name: '成本价',
          value: 'gearbox',
          type: 'text'
        },
        {
          name: '库存数量',
          value: 'clientName',
          type: 'text'
        },
        {
          name: '供应商',
          value: 'clientPhone',
          type: 'text'
        },
        {
          name: '供应商编号',
          value: 'clientName',
          type: 'text'
        },
        {
          name: '创建人',
          value: 'clientPhone',
          type: 'text'
        }
      ],
      dict: {}
    }
  },
  methods: {
    async handleCarBrand(val) {
      val && await getSeries(val).then((res) => {
        const { success, data } = res
        if (success) this.allSeries = data
      })
    },
    // 查看置换订单
    handleDetails(row) {
      const { id } = row
      this.$router.push({
        path: '/orderManagement/deatailReplacementOrder',
        query: {
          userId: id
        }
      })
    },
    // 查询
    search(form) {
      this.searchOptions = form
      this.currentPage = 1
      this.setTableData()
    },
    add() {

    }
  },
  async mounted() {
    await getAllBrand().then((res) => {
      const { success, data } = res
      if (success) this.allBrand = data
    })
  }
}
</script>
